import React, {Component, PropTypes} from 'react';
import Signals from 'signals';
import styles from './Main.less';
import ImageTreeContainer from '../Tree/ImageTreeContainer';
import ImageInfoComtainer from '../ImageInfo/ImageInfoComtainer';
import {getImageInfo, getColumns} from "../../services/showServer";

class ImageMainContainer extends React.Component {
  constructor(props) {
    super(props);
    //signals事件
    this.signal = new Signals.Signal();
    this.confirmsignal = new Signals.Signal();
  }

  componentWillMount() {
    this.signal.add(function (info) {
      getImageInfo(info).then(function (json) {
        if (json.type == 3) {
          getColumns(info).then(function (json) {
            this.refs.image.setState({
              type: 3,
              data: json
            });
          }.bind(this));
        } else {
          this.refs.image.setState({
            type: json.type,
            data: json
          });
        }
      }.bind(this));
    }.bind(this));

    this.confirmsignal.add(function (info) {
      getImageInfo(info).then(function (json) {
        if (json.type == 3) {
          getColumns(info).then(function (json) {
            this.refs.image.setState({
              type: 3,
              data: json
            });
          }.bind(this));
        } else {
          this.refs.image.setState({
            type: json.type,
            data: json
          });
        }
      }.bind(this));
      this.refs.tree.refreshData()
    }.bind(this));
  }

  componentWillUnmount() {
    this.signal.removeAll();
    this.confirmsignal.removeAll();
  }

  render() {
    return (
      <div className={styles.content}>
        <div className={styles.image_side}>
          <ImageTreeContainer signal={this.signal} ref="tree"/>
        </div>
        <div className={styles.image_main}>
          <ImageInfoComtainer signal={this.confirmsignal} ref="image"/>
        </div>
        {/*<div className={styles.main}>*/}
        {/*<CatTableComponent/>*/}
        {/*</div>*/}
      </div>
    );
  }
}

export default ImageMainContainer;
